﻿Imports System.Data.SqlClient
Imports DTO

Public Class DangNhapDAO
    Dim con As New DataProvider

    Public Function GetByID(ByVal id As String) As DangNhapDTO

        Dim para = New SqlParameter("@TenDN", id)
        Dim dt = con.ExecuteQuery("logintheoten", para)
        Dim login As New DangNhapDTO()
        If dt.Rows.Count <> 0 Then
            login.TenDN = dt.Rows(0).Item("TenDN").ToString()
            login.MatKhau = dt.Rows(0).Item("MatKhau").ToString()
            login.Quyen = dt.Rows(0).Item("Quyen").ToString()
            login.TrangThai = Boolean.Parse(dt.Rows(0).Item("isdelete"))
        End If
        Return login
    End Function

    Function LayTTUser(ByVal user As DangNhapDTO) As DangNhapDTO
        Dim dt As New DataTable
        Dim para As SqlParameter() = New SqlParameter(2) {}
        para(0) = New SqlParameter("TenDN", user.TenDN)
        para(1) = New SqlParameter("MatKhau", user.MatKhau)
        dt = con.ExecuteQuery("DangNhap", para)
        Dim login As New DangNhapDTO()
        If dt.Rows.Count <> 0 Then
            login.TenDN = dt.Rows(0).Item("TenDN").ToString()
            login.MatKhau = dt.Rows(0).Item("MatKhau").ToString()
            login.Quyen = dt.Rows(0).Item("Quyen").ToString()
        End If
        Return login

    End Function

    Sub Them(ByVal pxdto As DangNhapDTO)
        Dim cn As New DataProvider()
        Dim para As SqlParameter() = New SqlParameter(5) {}
        para(0) = New SqlParameter("@TenDN", pxdto.TenDN)
        para(1) = New SqlParameter("@MatKhau", pxdto.MatKhau)
        para(2) = New SqlParameter("@MaNV", pxdto.MaNhanVien)
        para(3) = New SqlParameter("@HoTen", pxdto.HoTenNhanVien)
        para(4) = New SqlParameter("@SDT", pxdto.SDT)
        para(5) = New SqlParameter("Quyen", pxdto.Quyen)
        cn.ExecuteNonQuery("InsertTK", para)
    End Sub



    Function loadtk() As DataTable
        Dim kh As New DataTable
        kh = con.ExecuteQuery("Loadtk", Nothing)
        Return kh
    End Function

    Sub Xoa(ByVal nv As DangNhapDTO)
        Dim cn As New DataProvider()
        Dim para = New SqlParameter("@TenDN", nv.TenDN)
        cn.ExecuteNonQuery("DeleteTK", para)
    End Sub

   

 

End Class
